;(function($) {
	$.extend({
		omnibox : {
			options : {},
			match : function(string, regex) {
				return string.match(new RegExp(regex, "g")) === null ? false : true;
			},
			check : function(strUrl) {
				if(this.match(strUrl, "^[A-Za-z0-9]+://") === true)
					return true;
				if(this.match(strUrl, "^([A-Za-z0-9]+(-*[A-Za-z0-9]+)*\\.)+[A-Za-z]{2,4}(\\/+.*|\\/*)?$") === true)
					return true;
				return false;
			},
			search : function(strKeyword) {
				chrome.tabs.create({
					"url" : "https://www.google.com.hk/search?sourceid=chrome&ie=UTF-8&q=" + strKeyword,
					"active" : this.options.active || false
				});
			},
			browse : function(strUrl) {
				chrome.tabs.create({
					"url" : strUrl,
					"active" : this.options.active || false

				});
			},
			smart : function(strSelection, blnActive) {
				this.options = {
					"active" : blnActive
				}
				if(this.check(strSelection) === true)
					this.browse(strSelection);
				else
					this.search(strSelection);
			},
			select : function(strSelection) {
				alert(strSelection);
			}
		}
	});
	chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
		var shortcut = request.shortcut;

		if($.shortcut.exists(shortcut) === false)
			return false;

		var strSelection = request.strSelection;

		if(shortcut === $.opt.shortcut.smartActive())
			$.omnibox.smart(strSelection, true);
		if(shortcut === $.opt.shortcut.smart())
			$.omnibox.smart(strSelection);
		if(shortcut === $.opt.shortcut.select())
			$.omnibox.select(strSelection);

	});
})(jQuery);
